package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.lkx.liandianqinew.R;

public class MyImgColorView extends LinearLayout {
    private Context mContext;
    private ImageView mImgBg;
    private ImageView mImgChose;
    private boolean mIsCheck;
    private onItemClickListener mOnItemClickListener;

    public interface onItemClickListener {
        void onClick(boolean z);
    }

    public MyImgColorView(Context context) {
        super(context);
    }

    public void setOnItemClickListener(onItemClickListener onitemclicklistener) {
        this.mOnItemClickListener = onitemclicklistener;
    }

    public MyImgColorView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.mContext = context;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MyImgColorView);
        this.mIsCheck = obtainStyledAttributes.getBoolean(R.styleable.MyImgColorView_y_cImgCheck, false);
        int color = obtainStyledAttributes.getColor(R.styleable.MyImgColorView_y_cImgColor, -65536);
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_img_color, (ViewGroup) this, true);
        this.mImgBg = (ImageView) inflate.findViewById(R.id.v_img_bg);
        this.mImgChose = (ImageView) inflate.findViewById(R.id.v_img_chose);
        this.mImgBg.setColorFilter(color);
        if (this.mIsCheck) {
            this.mImgChose.setVisibility(View.VISIBLE);
        } else {
            this.mImgChose.setVisibility(View.GONE);
        }
        inflate.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyImgColorView.AnonymousClass1 */

            public void onClick(View view) {
                MyImgColorView myImgColorView = MyImgColorView.this;
                myImgColorView.mIsCheck = !myImgColorView.mIsCheck;
                if (MyImgColorView.this.mIsCheck) {
                    MyImgColorView.this.mImgChose.setVisibility(View.VISIBLE);
                } else {
                    MyImgColorView.this.mImgChose.setVisibility(View.GONE);
                }
                if (MyImgColorView.this.mOnItemClickListener != null) {
                    MyImgColorView.this.mOnItemClickListener.onClick(MyImgColorView.this.mIsCheck);
                }
            }
        });
    }

    public void setCheck(boolean z) {
        this.mIsCheck = z;
        if (z) {
            this.mImgChose.setVisibility(View.VISIBLE);
        } else {
            this.mImgChose.setVisibility(View.GONE);
        }
    }

    public void setColorFilter(String str) {
        try {
            if (this.mImgBg != null) {
                if (!str.contains("#")) {
                    str = "#" + str;
                }
                this.mImgBg.setColorFilter(Color.parseColor(str));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
